import java.util.LinkedList;
import java.util.Queue;
import java.util.Stack;

class a2 {
   public static void main(String[] args){
        String s ="[[]8[]9[]9]3";
        LinkedList<Integer> stackd = new LinkedList<>();
        LinkedList<Integer> stackv = new LinkedList<>();
        int ans = 0;
        int deep = 0;
        for (int i = 0; i < s.length(); i++) {
            char tem = s.charAt(i);
            if (tem == '[') {
                deep = deep + 1;
            } else if (tem ==']') {
                stackd.add(deep);
                stackv.add(s.charAt(i + 1) - '0');
                deep = deep - 1;
            }
        }
        while (stackd.size() != 1) {
            for (int i = 0; i < stackd.size() - 1; i++) {
                if (stackd.get(i) == stackd.get(i + 1)) {
                    stackd.remove(i);
                    int tem = stackv.get(i + 1);
                    int tem2 = stackv.get(i);
                    stackv.remove(i + 1);
                    stackv.remove(i);
                    stackv.add(i, tem + tem2);
                    i--;
                    break;
                } else if (stackd.get(i) == stackd.get(i + 1) + 1) {
                    int d = stackd.get(i + 1);
                    stackd.remove(i);
                    int tem = stackv.get(i + 1);
                    int tem2 = stackv.get(i);
                    stackv.remove(i+1);
                    stackv.remove(i);
                    stackv.add(i, tem * tem2 + tem);
                    i--;
                    break;
                }
            }
        }
       System.out.println(stackv.get(0));
    }

}
